package date;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import net.sunniwell.tools.date.DateUtil;

/**
 * 列出两个日期之间的每一天
 * 
 * @author zhaoyujie
 *
 */
public class ListEveryBetweenDays {
	public static Date[] getDateArrays(Date start, Date end, int calendarType) {
		ArrayList<Date> ret = new ArrayList<Date>();
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(start);
		Date tmpDate = calendar.getTime();
		long endTime = end.getTime();
		while (tmpDate.before(end) || tmpDate.getTime() == endTime) {
			ret.add(calendar.getTime());
			calendar.add(calendarType, 1);
			tmpDate = calendar.getTime();
		}

		Date[] dates = new Date[ret.size()];
		return ret.toArray(dates);
	}

	public static void main(String[] args) {

		Date date = DateUtil.stringToDate("2008-04-01");
		Date date2 = DateUtil.stringToDate("2008-04-07");
		Date[] strArray = getDateArrays(date, date2, Calendar.DAY_OF_YEAR);
		for (Date date3 : strArray) {
			System.out.println(DateUtil
					.dateToString(date3, false, "yyyy-MM-dd"));
		}
	}
}
